// 导入 Sequelize 和数据库连接配置
const { DataTypes } = require('sequelize');
const { sequelize } = require('../init'); // 导入数据库连接配置
const { Resource } = require('../model/Resource')
const { MainMenu } = require('../model/MainMenu')

// 创建主菜单子菜单关联表模型
const MainMenuSubMenu = sequelize.define('MainMenuSubMenu', {
    MainMenuID: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        allowNull: false,
        references: {
            model: MainMenu,
            key: 'MenuID'
        }
    },
    SubMenuID: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        allowNull: false,
        references: {
            model: Resource,
            key: 'ResourceID'
        }
    }
}, {
    tableName: 'mainmenu_submenu',
    timestamps: false,
    collate: 'utf8mb4_bin'
});

// 帮我打印一下数据库连接情况
MainMenuSubMenu.sync({ force: false }).then(() =>
{
    console.log('主菜单资源映射表准备');
});

module.exports = { MainMenuSubMenu };